
const classifyModel = require('../model/classifyModel');

// 增加
module.exports.insert = async function (classify) {
    return await classifyModel.create(classify);//注：create     
}

// 查找
module.exports.findBysort=async function(sort){
    return await classifyModel.find({sort});//注：username要转为对象
}
// 删除
module.exports.remove = async function (id) {
    return await classifyModel.remove({ _id: id });
}

// 搜索
module.exports.find = async function (searchObj, page) {//page分页参数
    let { current, pageSize } = page;
    //根据查询条件获取总数
    let total = await classifyModel.countDocuments(searchObj);
    //根据查询条件获取具体数量的数据
    let data = await classifyModel.find(searchObj)
        .limit(pageSize)
        .skip((current - 1) * pageSize);
    return {
        current, pageSize, total, rows: data,
    }
}
// 搜索全部
module.exports.findAll = async function (params) {
    return await classifyModel.find(params);
}

// 修改搜索
module.exports.findById = async function (id) {
    return await classifyModel.findById(id);
}
//修改
module.exports.update = async function (id, classify) {
    return await classifyModel.updateOne({ _id: id }, classify);
}
